package com.ruoyi.bom.service.impl;

import com.ruoyi.bom.domain.*;
import com.ruoyi.bom.dto.BillFoodPeriodDto;
import com.ruoyi.bom.dto.DeptProlossAndMarginDto;
import com.ruoyi.bom.mapper.BomAnalsysMapper;
import com.ruoyi.bom.service.TqlFoodService;
import com.ruoyi.bom.mapper.TqlFoodMapper;
import com.ruoyi.common.core.constant.CommonUtil;
import com.ruoyi.common.core.utils.TimeUtils;
import com.ruoyi.common.datasource.annotation.Master;
import com.ruoyi.common.datasource.annotation.Slave;
import io.github.classgraph.HasName;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author 86198
* @description 针对表【tql_food】的数据库操作Service实现
* @createDate 2024-01-18 18:19:03
*/
@Service
public class TqlFoodServiceImpl implements TqlFoodService{

    @Resource
    private TqlFoodMapper tqlFoodMapper;

    @Resource
    private BomAnalsysMapper bomAnalsysMapper;

    @Override
    public List<TqlFood> selectFoodList(TqlFood tqlFood) {
        List<TqlFood> foodList = tqlFoodMapper.selectFoodList(tqlFood);
        return foodList;
    }


    /**
     * 查询菜品
     * @param tqlFood
     * @return
     */
    @Override
    public List<TqlFood> selectFoodVoList(TqlFood tqlFood) {
        return tqlFoodMapper.selectFoodVoList(tqlFood);
    }

    @Override
    public List<TqlFood> selectShopAndPriceList(TqlFood tqlFood) {
        return tqlFoodMapper.selectShopAndPriceList(tqlFood);
    }

    @Override
    public List<TqlFood> findAllFood(Map<String, String> params) {
        return tqlFoodMapper.findAllFood(params);
    }

    @Override
    public List<TqlFood> findAllFood(TqlFood params) {
        return tqlFoodMapper.selectAllFoodByIsLock(params);
    }

    @Override
    public List<TqlFoodUnit> findFoodUnit(Long foodId) {
        return tqlFoodMapper.findFoodUnit(foodId);
    }

    @Override
    public List<TqlFood> findUnUserFoodInfo(String fnumber) {
        return tqlFoodMapper.findUnUserFoodInfo(fnumber);
    }

    @Override
    public TqlPandianPeriodVO findEnableGenPharse(String pandianCode) {
        return tqlFoodMapper.findEnableGenPharse(pandianCode);
    }

    @Override
    @Slave
    public FoodAndBom findUnUserFoodCountAndSumAmount(FoodAndBom food,TqlPandianPeriodVO period,int month) {
        String billFoodTableName= CommonUtil.TableName_ShopBillFoodReportDayDetail+month;
        HashMap<String,Object> map=new HashMap<>();
        map.put("stattime", TimeUtils.getStringDateToLong(period.getStarttime()));
        map.put("endtime",TimeUtils.getStringDateToLong(period.getEndtime()));
        map.put("shopID",period.getKindeeShopCode());
        map.put("foodCode",food.getFoodCode());
        map.put("tabName",billFoodTableName);
        return tqlFoodMapper.findUnUserFoodCountAndSumAmount(map);
    }

    @Slave
//tql_hll_shop_bill_food_reportday2
    public  List<FoodAndBom> findTqlHllShopBillFoodReportByPeriod(TqlPandianPeriodVO period, int month) {
        String billFoodTableName= CommonUtil.TableName_ShopBillFoodReportDayDetail+month;
        HashMap<String,Object> map=new HashMap<>();
        map.put("stattime", TimeUtils.getStringDateToLong(period.getStarttime()));
        map.put("endtime",TimeUtils.getStringDateToLong(period.getEndtime()));
        map.put("shopID",period.getKindeeShopCode());
//        map.put("foodCode",food.getFoodCode());
        map.put("tabName",billFoodTableName);
        return tqlFoodMapper.findTqlHllShopBillFoodReportByPeriod(map);
    }

    @Override
    public List<FoodAndBom> findBomCardParse(String pandianCode, String type) {
        return bomAnalsysMapper.findBomCardParse(pandianCode,type);
    }

    @Override
    public List<DeptProlossAndMarginDto> findDeptProloss(String pandianCode, String shopCode) {
        return bomAnalsysMapper.findDeptProloss(pandianCode,shopCode);
    }

    @Override
    @Master
    public String getLastPandianCode(String pandianCode) {
        return bomAnalsysMapper.getLastPandianCode(pandianCode);
    }

    @Override
    public List<DeptProlossAndMarginDto> findRealCost(String pandianCode, String[] deptCodes) {
        return bomAnalsysMapper.findRealCost(pandianCode,deptCodes);
    }

    @Override
    public int insertDeptProlossAndMargin(List<DeptProlossAndMarginDto> list) {
        return bomAnalsysMapper.insertDeptProlossAndMargin(list);
    }

    @Override
    public List<DeptProlossAndMarginDto> findDeptProlossAndMargin(String pandianCode) {
        return bomAnalsysMapper.findDeptProlossAndMargin(pandianCode);
    }

    @Override
    public int delDeptProlossAndMargin(String pandianCode) {
        return bomAnalsysMapper.delDeptProlossAndMargin(pandianCode);
    }

    @Override
    public void setIsOpen(Integer id) {
         tqlFoodMapper.updatesetIsOpen(id);
    }


    @Override
    public int insertBomAnalsysByUnusedBom(List<FoodAndBom> list1) {
        return bomAnalsysMapper.insertBomAnalsysByUnusedBom(list1);
    }

    @Override
    public List<FoodAndBom> queryBomAnalsys(FoodAndBom bom) {

        return bomAnalsysMapper.queryBomAnalsys(bom);
    }

    @Override
    public List<BillFoodPeriodDto> findBillFoodPeriod(String pandianCode,String[] t) {

        return bomAnalsysMapper.findBillFoodPeriod(pandianCode, t);
    }

}




